/*
  ******************************************************************************
  * @file    apt32f172_interrupt.c
  * @author  APT AE Team
  * @version V1.12
  * @date    2019/03/08
  ******************************************************************************
  *THIS SOFTWARE WHICH IS FOR ILLUSTRATIVE PURPOSES ONLY WHICH PROVIDES 
  *CUSTOMER WITH CODING INFORMATION REGARDING THEIR PRODUCTS.
  *APT CHIP SHALL NOT BE HELD RESPONSIBILITY ADN LIABILITY FOR ANY DIRECT, 
  *INDIRECT DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF 
  *SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION 
  *CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.AND APT CHIP RESERVES 
  *THE RIGHT TO MAKE CHANGES IN THE SOFTWARE WITHOUT NOTIFICATION
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "apt32f172.h"
#include "apt32f172_types_local.h"
#include "apt32f172_coret.h"
#include "apt32f172_ifc.h"
#include "apt32f172_syscon.h"
#include "apt32f172_adc.h"
#include "apt32f172_cmp.h"
#include "apt32f172_oamp.h"
#include "apt32f172_gpio.h"
#include "apt32f172_tc0_gpt.h"
#include "apt32f172_tc1_gtc.h"
#include "apt32f172_tc2_st16.h"
#include "apt32f172_tc3_ctc.h"
#include "apt32f172_epwm.h"
#include "apt32f172_led.h"
#include "apt32f172_i2c.h"
#include "apt32f172_spi.h"
#include "apt32f172_usart.h"
#include "apt32f172_uart.h"
/* externs--------------------------------------------------------------------*/
extern volatile U8_T SYSCON_ISOSCSTFlag;
extern volatile U8_T SYSCON_IMOSCSTFlag;
extern volatile U8_T SYSCON_EMOSCSTFlag;
extern volatile U8_T SYSCON_SYSCLKSTFlag;
extern volatile U8_T SYSCON_IWDTINTFlag;
extern volatile U8_T SYSCON_LVDINTFlag;
extern volatile U8_T SYSCON_EM_CMFAILFlag;
extern volatile U8_T SYSCON_EM_CMRCVFlag;
extern volatile U8_T SYSCON_CMD_ERRFlag;

extern volatile U8_T SPI_PORIMIFlag;
extern volatile U8_T SPI_RTIMIFlag;
extern volatile U8_T SPI_RXIMIFlag;
extern volatile U8_T SPI_TXIMIFlag;

extern volatile U8_T I2C_INTFlag ;					
extern volatile U8_T I2CMode;
extern volatile U8_T restart;

volatile unsigned int RA_Capture,RB_Capture,R_LowLevel_T,R_HighLevel_T,SPI_DATA[8];
volatile U32_T 	R_Uart_RDBUF;
volatile U32_T  R_Capture_buf1,R_Capture_buf2,R_Capture_buf3,f_GTC_CaptTrigg;
volatile U8_T r_usrat_cont,r_urat_cont;
volatile U8_T r_usart_buf[3];
volatile U8_T r_uart_buf[3];
volatile U8_T R_timer_4ms;

/*************************************************************/
//CORET Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void CORETHandler(void) 
{
    // ISR content ...
	
	CK801->CORET_CVR = 0;							// Coret CVR 清除
}
/*************************************************************/
//SYSCON Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SYSCONIntHandler(void) 
{
    // ISR content ...
	 if((SYSCON->ISR&ISOSC_ST)==ISOSC_ST)
    {
        SYSCON->ICR = ISOSC_ST;
        SYSCON_ISOSCSTFlag=1;
    } 
    else if((SYSCON->ISR&IMOSC_ST)==IMOSC_ST)
    {
        SYSCON->ICR = IMOSC_ST;
        SYSCON_IMOSCSTFlag=1;
    } 
    else if((SYSCON->ISR&EMOSC_ST)==EMOSC_ST)
    {
        SYSCON->ICR = EMOSC_ST;
        SYSCON_EMOSCSTFlag=1;
    } 
    else if((SYSCON->ISR&SYSCLK_ST)==SYSCLK_ST)
    {
        SYSCON->ICR = SYSCLK_ST;
        SYSCON_SYSCLKSTFlag=1;
    }
    else if((SYSCON->ISR&IWDT_INT_ST)==IWDT_INT_ST)
    {
        SYSCON->ICR = IWDT_INT_ST;
        SYSCON_IWDTINTFlag=1;
		//SYSCON_IWDCNT_Reload();                                                     //reload WDT
    }
    else if((SYSCON->ISR&LVD_INT_ST)==LVD_INT_ST)
    {
        SYSCON->ICR = LVD_INT_ST;
        SYSCON_LVDINTFlag=1;
    }
    else if((SYSCON->ISR&EM_CMFAIL_ST)==EM_CMFAIL_ST)
    {
        SYSCON->ICR = EM_CMFAIL_ST;
        SYSCON_EM_CMFAILFlag=1;
    }
    else if((SYSCON->ISR&EM_CMRCV_ST)==EM_CMRCV_ST)
    {
        SYSCON->ICR = EM_CMRCV_ST;
        SYSCON_EM_CMRCVFlag=1;
    }
    else if((SYSCON->ISR&CMD_ERR_ST)==CMD_ERR_ST)
    {
        SYSCON->ICR = CMD_ERR_ST;
        SYSCON_CMD_ERRFlag=1;
    }
}
/*************************************************************/
//IFC Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void IFCIntHandler(void)
{
    // ISR content ...
	if((IFC->MISR&End_INT)==End_INT)
    {
        IFC->ICLR = End_INT;
    } else if((IFC->MISR&Port_INT)==Port_INT)
    {
        IFC->ICLR = Port_INT;
    } else if((IFC->MISR&Undefine_INT)==Undefine_INT)
    {
        IFC->ICLR = Undefine_INT;
    } else if((IFC->MISR&Add_INT)==Add_INT)
    {
        IFC->ICLR = Add_INT;
    } else if((IFC->MISR&OverWrite_INT)==OverWrite_INT)
    {
        IFC->ICLR = OverWrite_INT;
    }
}
/*************************************************************/
//EXI0 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI0IntHandler(void) 
{
    // ISR content ...
	if ((SYSCON->EXIRS&EXI_PIN0)==EXI_PIN0) 
    {
        SYSCON->EXICR = EXI_PIN0;
    }
}
/*************************************************************/
//EXI1 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI1IntHandler(void) 
{
    // ISR content ...
	if ((SYSCON->EXIRS&EXI_PIN1)==EXI_PIN1) 
    {
        SYSCON->EXICR = EXI_PIN1;
    }
}
/*************************************************************/
//EXI2~EXI3 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI2to3IntHandler(void) 
{
    // ISR content ...
	if ((SYSCON->EXIRS&EXI_PIN2)==EXI_PIN2) 
    {
        SYSCON->EXICR = EXI_PIN2;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN3)==EXI_PIN3) 
    {
        SYSCON->EXICR = EXI_PIN3;
    }
}
/*************************************************************/
//EXI4~EXI9 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI4to9IntHandler(void) 
{
    // ISR content ...
	if ((SYSCON->EXIRS&EXI_PIN4)==EXI_PIN4) 
    {
        SYSCON->EXICR = EXI_PIN4;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN5)==EXI_PIN5) 
    {
        SYSCON->EXICR = EXI_PIN5;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN6)==EXI_PIN6) 
    {
        SYSCON->EXICR = EXI_PIN6;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN7)==EXI_PIN7) 
    {
        SYSCON->EXICR = EXI_PIN7;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN8)==EXI_PIN8) 
    {
        SYSCON->EXICR = EXI_PIN8;
    }
	else if ((SYSCON->EXIRS&EXI_PIN9)==EXI_PIN9) 
	{
        SYSCON->EXICR = EXI_PIN9;
	}
}
/*************************************************************/
//EXI10~EXI15 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EXI10to15IntHandler(void) 
{
    if ((SYSCON->EXIRS&EXI_PIN10)==EXI_PIN10) 
    {
        SYSCON->EXICR = EXI_PIN10;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN11)==EXI_PIN11) 
    {
        SYSCON->EXICR = EXI_PIN11;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN12)==EXI_PIN12) 
    {
        SYSCON->EXICR = EXI_PIN12;
    } 
    else if ((SYSCON->EXIRS&EXI_PIN13)==EXI_PIN13) 
    {
        SYSCON->EXICR = EXI_PIN13;
    }
	else if ((SYSCON->EXIRS&EXI_PIN14)==EXI_PIN14) 
    {
        SYSCON->EXICR = EXI_PIN14;
    }
	else if ((SYSCON->EXIRS&EXI_PIN15)==EXI_PIN15) 
	{
        SYSCON->EXICR = EXI_PIN15;
    }
}
/*************************************************************/
//USART0 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void USART0IntHandler(void) 
{
    // ISR content ...
	unsigned int status;
	status = USART0->MISR & USART0->IMSCR ;
	if( status & USART_RXRDY ) 
	{
	   r_usrat_cont++;
		if(r_usrat_cont>=3)
		{
			r_usrat_cont=0;
		}
		r_usart_buf[r_usrat_cont]=CSP_USART_GET_RHR(USART0);
		CSP_USART_SET_ICR(USART0, USART_RXRDY);
	}
	if (status & USART_TXRDY) 
	{
		//CSP_USART_SET_ICR(USART0, USART_TXRDY);
	}
}
/*************************************************************/
//UART1 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void UART1IntHandler(void) 
{
	// ISR content ...
	if (UART1->ISR&UART_RX_INT_S)
	{
		r_urat_cont++;
		if(r_urat_cont>=3)
		{
			r_urat_cont=0;
		}
		r_uart_buf[r_urat_cont]=CSP_UART_GET_DATA(UART1);
		UART1->ISR=UART_RX_INT_S;
	}
	if( UART1->ISR&UART_TX_INT_S) 
    {
		//UART1->ISR=UART_TX_INT_S;
	}
	if ((UART1->ISR&UART_RX_IOV_S)==UART_RX_IOV_S)
	{
		UART1->ISR=UART_RX_IOV_S;
	}
	if ((UART1->ISR&UART_TX_IOV_S)==UART_TX_IOV_S)
	{
		UART1->ISR=UART_TX_IOV_S;
	}
	if ((UART1->ISR&UART_PAR_ERR_S)==UART_PAR_ERR_S)
	{
		UART1->ISR=UART_PAR_ERR_S;
	}
}
/*************************************************************/
//I2C Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void I2CIntHandler(void) 
{
     // i2c master
    /*if (I2CMode==1)
    {
		I2C_INTFlag=1;
		if(restart==1) 
		{
			I2C0->CR = (I2C0->CR & (~I2C_SI)) | I2C_STA ;
			restart=0;
		} 
		else 
		{
			I2C0->CR = I2C0->CR & (~I2C_SI);
		}
    }*/
    //I2C slave
    //else if (I2CMode==0)
   // {
		I2C_Slave_Receive();
   // }
}
/*************************************************************/
//GPT_0 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void GPT_0IntHandler(void) 
{
    // ISR content ...
	if((GPTCH0->SR&GPTCHX_INT_COVFS)==GPTCHX_INT_COVFS)
	{
		GPTCH0->CSR = GPTCHX_INT_COVFS;
	}
	if((GPTCH0->SR&GPTCHX_INT_LOVRS)==GPTCHX_INT_LOVRS)
	{
		GPTCH0->CSR = GPTCHX_INT_LOVRS;
	}
	if((GPTCH0->SR&GPTCHX_INT_CPAS)==GPTCHX_INT_CPAS)
	{
		GPTCH0->CSR = GPTCHX_INT_CPAS;
	}
	if((GPTCH0->SR&GPTCHX_INT_CPBS)==GPTCHX_INT_CPBS)
	{
		GPTCH0->CSR = GPTCHX_INT_CPBS;
	}
	if((GPTCH0->SR&GPTCHX_INT_CPCS)==GPTCHX_INT_CPCS)
	{
		GPTCH0->CSR = GPTCHX_INT_CPCS;
	}
	if((GPTCH0->SR&GPTCHX_INT_LDRAS)==GPTCHX_INT_LDRAS)
	{
		GPTCH0->CSR = GPTCHX_INT_LDRAS;
		//RA_Capture=GPTCH0->RA;
	}
	if((GPTCH0->SR&GPTCHX_INT_LDRBS)==GPTCHX_INT_LDRBS)
	{
		GPTCH0->CSR = GPTCHX_INT_LDRBS;
		//RB_Capture=GPTCH0->RB;
	}
	if((GPTCH0->SR&GPTCHX_INT_ETRGS)==GPTCHX_INT_ETRGS)
	{
		GPTCH0->CSR = GPTCHX_INT_ETRGS;
	}
}
/*************************************************************/
//GPT_1 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void GPT_1IntHandler(void) 
{
	// ISR content ...
	if((GPTCH1->SR&GPTCHX_INT_COVFS)==GPTCHX_INT_COVFS)
	{
		GPTCH1->CSR = GPTCHX_INT_COVFS;
	}
	if((GPTCH1->SR&GPTCHX_INT_LOVRS)==GPTCHX_INT_LOVRS)
	{
		GPTCH1->CSR = GPTCHX_INT_LOVRS;
	}
	if((GPTCH1->SR&GPTCHX_INT_CPAS)==GPTCHX_INT_CPAS)
	{
		GPTCH1->CSR = GPTCHX_INT_CPAS;
	}
	if((GPTCH1->SR&GPTCHX_INT_CPBS)==GPTCHX_INT_CPBS)
	{
		GPTCH1->CSR = GPTCHX_INT_CPBS;
	}
	if((GPTCH1->SR&GPTCHX_INT_CPCS)==GPTCHX_INT_CPCS)
	{
		GPTCH1->CSR = GPTCHX_INT_CPCS;
	}
	if((GPTCH1->SR&GPTCHX_INT_LDRAS)==GPTCHX_INT_LDRAS)
	{
		GPTCH1->CSR = GPTCHX_INT_LDRAS;
	}
	if((GPTCH1->SR&GPTCHX_INT_LDRBS)==GPTCHX_INT_LDRBS)
	{
		GPTCH1->CSR = GPTCHX_INT_LDRBS;
	}
	if((GPTCH1->SR&GPTCHX_INT_ETRGS)==GPTCHX_INT_ETRGS)
	{
		GPTCH1->CSR = GPTCHX_INT_ETRGS;
	}
}
/*************************************************************/
//GPT_2 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void GPT_2IntHandler(void) 
{
    // ISR content ...
	if((GPTCH2->SR&GPTCHX_INT_COVFS)==GPTCHX_INT_COVFS)
	{
		GPTCH2->CSR = GPTCHX_INT_COVFS;
	}
	if((GPTCH2->SR&GPTCHX_INT_LOVRS)==GPTCHX_INT_LOVRS)
	{
		GPTCH2->CSR = GPTCHX_INT_LOVRS;
	}
	if((GPTCH2->SR&GPTCHX_INT_CPAS)==GPTCHX_INT_CPAS)
	{
		GPTCH2->CSR = GPTCHX_INT_CPAS;
	}
	if((GPTCH2->SR&GPTCHX_INT_CPBS)==GPTCHX_INT_CPBS)
	{
		GPTCH2->CSR = GPTCHX_INT_CPBS;
	}
	if((GPTCH2->SR&GPTCHX_INT_CPCS)==GPTCHX_INT_CPCS)
	{
		GPTCH2->CSR = GPTCHX_INT_CPCS;
	}
	if((GPTCH2->SR&GPTCHX_INT_LDRAS)==GPTCHX_INT_LDRAS)
	{
		GPTCH2->CSR = GPTCHX_INT_LDRAS;
	}
	if((GPTCH2->SR&GPTCHX_INT_LDRBS)==GPTCHX_INT_LDRBS)
	{
		GPTCH2->CSR = GPTCHX_INT_LDRBS;
	}
	if((GPTCH2->SR&GPTCHX_INT_ETRGS)==GPTCHX_INT_ETRGS)
	{
		GPTCH2->CSR = GPTCHX_INT_ETRGS;
	}
}
/*************************************************************/
//GTC Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void GTCIntHandler(void) 
{
    // ISR content ...
	if((GTC->MISR&GTC_PENDI)==GTC_PENDI)
	{
		GTC->ICR = GTC_PENDI;
	} 
	if((GTC->MISR&GTC_STOPI)==GTC_STOPI)
	{
		GTC->ICR = GTC_STOPI;
	} 
	if((GTC->MISR&GTC_OVFI)==GTC_OVFI)
	{
		GTC->ICR = GTC_OVFI;
	} 
	if((GTC->MISR&GTC_STARTI)==GTC_STARTI)
	{
		GTC->ICR = GTC_STARTI;
	}
	if((GTC->MISR&GTC_PSTARTI)==GTC_PSTARTI)
	{
		GTC->ICR = GTC_PSTARTI;
	}
	if((GTC->MISR&GTC_MATI)==GTC_MATI)
	{
		GTC->ICR = GTC_MATI;
	}
	if((GTC->MISR&GTC_CAPTI)==GTC_CAPTI)
	{
		GTC->ICR = GTC_CAPTI;
		/*if(!f_GTC_CaptTrigg)
		{
			f_GTC_CaptTrigg=1;
			R_Capture_buf1=GTC->CDCR;									//R_Capture_buf1 Period time
			GTC_ControlSet_Configure(GTC_ControlSet_CAPT_R,ENABLE);    	//capture down enable
			GTC_ControlSet_Configure(GTC_ControlSet_CAPT_F,DISABLE);
			GTC_Stop();
			GTC_Start();							//清除计数器
		}
		else
		{
			f_GTC_CaptTrigg=0;
			R_Capture_buf2=GTC->CUCR;								 	//R_Capture_buf2 Low level time
			GTC_ControlSet_Configure(GTC_ControlSet_CAPT_R,DISABLE);    //capture down enable
			GTC_ControlSet_Configure(GTC_ControlSet_CAPT_F,ENABLE);
		}
		if(R_Capture_buf1>R_Capture_buf2)								//R_Capture_buf3 High level time
		{
			R_Capture_buf3=R_Capture_buf1-R_Capture_buf2;
		}
		else
		{
			R_Capture_buf3=R_Capture_buf2-R_Capture_buf1;
		}*/
	}
}
/*************************************************************/
//STC16 Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void STC16IntHandler(void) 
{
    // ISR content ...
	
	
	if((ST16->MISR&ST16_STARTI)==ST16_STARTI)
	{
		ST16->ICR = ST16_STARTI;
	}
	else if((ST16->MISR&ST16_STOPI)==ST16_STOPI)
	{
		ST16->ICR = ST16_STOPI;
	}
	else if((ST16->MISR&ST16_PENDI)==ST16_PENDI)
	{
		ST16->ICR = ST16_PENDI;
	}
	else if((ST16->CMISR&ST16_CC0RI)==ST16_CC0RI)
	{
		ST16->CICR = ST16_CC0RI;
		//R_LowLevel_T=ST16->CC0R;
		//STC16_stop();
		//STC16_Channel0_Capture_LoadMode_set(STC16_C0SR_CaptureFall);				//stc16 Channel0下降沿捕捉
		//STC16_Start();
	}
	else if((ST16->CMISR&ST16_CC1RI)==ST16_CC1RI)
	{
		ST16->CICR = ST16_CC1RI;
	}
	else if((ST16->CMISR&ST16_CC0FI)==ST16_CC0FI)
	{
		ST16->CICR = ST16_CC0FI;
		//R_HighLevel_T=ST16->CC0R;
		//STC16_stop();
		//STC16_Channel0_Capture_LoadMode_set(STC16_C0SR_CaptureRise);				//stc16 Channel0下降沿捕捉
		//STC16_Start();
	}
	else if((ST16->CMISR&ST16_CC1FI)==ST16_CC1FI)
	{
		ST16->CICR = ST16_CC1FI;
	}
}
/*************************************************************/
//CTC Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void CTCIntHandler(void) 
{
    // ISR content ...
	if((CTC->MISR&CTC_INT_PEND)==CTC_INT_PEND)
	{
		CTC->ICR = CTC_INT_PEND;
		CTC->TIMDR=0;
	}
	else if((CTC->MISR&CTC_INT_OVF)==CTC_INT_OVF)
	{
		CTC->ICR = CTC_INT_OVF;
	}
}
/*************************************************************/
//ADC Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void ADCIntHandler(void) 
{
    // ISR content ...
	if((ADC0->SR&ADC12_EOC)==ADC12_EOC)
	{
		ADC0->CSR = ADC12_EOC;
	}
	else if((ADC0->SR&ADC12_READY)==ADC12_READY)
	{
		ADC0->CSR = ADC12_READY;
	}
	else if((ADC0->SR&ADC12_OVR)==ADC12_OVR)
	{
		ADC0->CSR = ADC12_OVR;
	}
	else if((ADC0->SR&ADC12_CMP0H)==ADC12_CMP0H)
	{
		ADC0->CSR = ADC12_CMP0H;
	}
	else if((ADC0->SR&ADC12_CMP0L)==ADC12_CMP0L)
	{
		ADC0->CSR = ADC12_CMP0L;
	}
	else if((ADC0->SR&ADC12_CMP1H)==ADC12_CMP1H)
	{
		ADC0->CSR = ADC12_CMP1H;
	}
	else if((ADC0->SR&ADC12_CMP1L)==ADC12_CMP1L)
	{
		ADC0->CSR = ADC12_CMP1L;
	}
}
/*************************************************************/
//LED Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void LEDIntHandler(void) 
{
    // ISR content ...
	if ((LED0->MISR &ICEND)==ICEND) 
    {
        LED0->ICR = ICEND;
    } 
    else if((LED0->MISR &IPEND)==IPEND) 
    {
        LED0->ICR = IPEND;
    } 
}
/*************************************************************/
//SPI Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void SPIIntHandler(void) 
{
    // ISR content ...
	if((SPI0->MISR&SPI_PORIM)==SPI_PORIM)					//接收溢出中断
	{
		SPI0->ICR = SPI_PORIM;
	} 
	else if((SPI0->MISR&SPI_RTIM)==SPI_RTIM)				//接收超时中断
	{
		SPI0->ICR = SPI_RTIM;
	}
	else if((SPI0->MISR&SPI_RXIM)==SPI_RXIM)				//接收FIFO中断,FIFO占用1/8,1/4,1/2中断
	{
		SPI0->ICR = SPI_RXIM;
		/*SPI_DATA[0]=SPI0->DR;
		SPI_DATA[1]=SPI0->DR;
		SPI_DATA[2]=SPI0->DR;
		SPI_DATA[3]=SPI0->DR;
		SPI_DATA[4]=SPI0->DR;
		SPI_DATA[5]=SPI0->DR;
		SPI_DATA[6]=SPI0->DR;
		SPI_DATA[7]=SPI0->DR;
		nop;*/
	}
	else if((SPI0->MISR&SPI_TXIM)==SPI_TXIM)				//发送FIFO中断
	{
		SPI0->ICR = SPI_TXIM;
	}
}
/*************************************************************/
//EPWM Interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void EPWMIntHandler(void) 
{
    // ISR content ...
	if ((EPWM->MISR & EPWM_START0)==EPWM_START0) 
    {
        EPWM->ICR = EPWM_START0;
    } 
    else if((EPWM->MISR & EPWM_STOP0)==EPWM_STOP0) 
    {
        EPWM->ICR = EPWM_STOP0;
    }
	else if((EPWM->MISR & EPWM_PEND0)==EPWM_PEND0) 
    {
        EPWM->ICR = EPWM_PEND0;
    } 
	else if((EPWM->MISR & EPWM_CENTER0)==EPWM_CENTER0) 
    {
        EPWM->ICR = EPWM_CENTER0;
    } 
	else if ((EPWM->MISR & EPWM_START1)==EPWM_START1) 
    {
        EPWM->ICR = EPWM_START1;
    } 
    else if((EPWM->MISR & EPWM_STOP1)==EPWM_STOP1) 
    {
        EPWM->ICR = EPWM_STOP1;
    }
	else if((EPWM->MISR & EPWM_PEND1)==EPWM_PEND1) 
    {
        EPWM->ICR = EPWM_PEND1;
    } 
	else if((EPWM->MISR & EPWM_CENTER1)==EPWM_CENTER1) 
    {
        EPWM->ICR = EPWM_CENTER1;
    } 
	else if ((EPWM->MISR & EPWM_START2)==EPWM_START2) 
    {
        EPWM->ICR = EPWM_START2;
    } 
    else if((EPWM->MISR & EPWM_STOP2)==EPWM_STOP2) 
    {
        EPWM->ICR = EPWM_STOP2;
    }
	else if((EPWM->MISR & EPWM_PEND2)==EPWM_PEND2) 
    {
        EPWM->ICR = EPWM_PEND2;
    } 
	else if((EPWM->MISR & EPWM_CENTER2)==EPWM_CENTER2) 
    {
        EPWM->ICR = EPWM_CENTER2;
    }
	else if((EPWM->MISR & EPWM0_CMPAUM)==EPWM0_CMPAUM) 
    {
        EPWM->ICR = EPWM0_CMPAUM;
    }
	else if((EPWM->MISR & EPWM0_CMPADM)==EPWM0_CMPADM) 
    {
        EPWM->ICR = EPWM0_CMPADM;
    }
	else if((EPWM->MISR & EPWM0_CMPBUM)==EPWM0_CMPBUM) 
    {
        EPWM->ICR = EPWM0_CMPBUM;
    }
	else if((EPWM->MISR & EPWM0_CMPBDM)==EPWM0_CMPBDM) 
    {
        EPWM->ICR = EPWM0_CMPBDM;
    }
	else if((EPWM->MISR & EPWM1_CMPAUM)==EPWM1_CMPAUM) 
    {
        EPWM->ICR = EPWM1_CMPAUM;
    }
	else if((EPWM->MISR & EPWM1_CMPADM)==EPWM1_CMPADM) 
    {
        EPWM->ICR = EPWM1_CMPADM;
    }
	else if((EPWM->MISR & EPWM1_CMPBUM)==EPWM1_CMPBUM) 
    {
        EPWM->ICR = EPWM1_CMPBUM;
    }
	else if((EPWM->MISR & EPWM1_CMPBDM)==EPWM1_CMPBDM) 
    {
        EPWM->ICR = EPWM1_CMPBDM;
    }
	else if((EPWM->MISR & EPWM2_CMPAUM)==EPWM2_CMPAUM) 
    {
        EPWM->ICR = EPWM2_CMPAUM;
    }
	else if((EPWM->MISR & EPWM2_CMPADM)==EPWM2_CMPADM) 
    {
        EPWM->ICR = EPWM2_CMPADM;
    }
	else if((EPWM->MISR & EPWM2_CMPBUM)==EPWM2_CMPBUM) 
    {
        EPWM->ICR = EPWM2_CMPBUM;
    }
	else if((EPWM->MISR & EPWM2_CMPBDM)==EPWM2_CMPBDM) 
    {
        EPWM->ICR = EPWM2_CMPBDM;
    }
	else if((EPWM->MISR & EPWM0_SLPA_OVF)==EPWM0_SLPA_OVF) 
    {
        EPWM->ICR = EPWM0_SLPA_OVF;
    }
	else if((EPWM->MISR & EPWM0_SLPB_OVF)==EPWM0_SLPB_OVF) 
    {
        EPWM->ICR = EPWM0_SLPB_OVF;
    }
	else if((EPWM->MISR & EPWM1_SLPA_OVF)==EPWM1_SLPA_OVF) 
    {
        EPWM->ICR = EPWM1_SLPA_OVF;
    }
	else if((EPWM->MISR & EPWM1_SLPB_OVF)==EPWM1_SLPB_OVF) 
    {
        EPWM->ICR = EPWM1_SLPB_OVF;
    }
}
/*************************************************************/
//CMP0,CMP2 interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void CMP0IntHandler(void) 
{
    // ISR content ...
	if ((CMP->MISR & EDGEDET0)==EDGEDET0) 
	{
		CMP->ICR =	EDGEDET0;
	}
	else if ((CMP->MISR & EDGEDET2)==EDGEDET2) 
	{
		CMP->ICR =	EDGEDET2;
	}
}
/*************************************************************/
//CMP1,CMP3,CMP4 interrupt
//EntryParameter:NONE
//ReturnValue:NONE
/*************************************************************/
void CMP1IntHandler(void) 
{
    // ISR content ...
	if((CMP->MISR & EDGEDET1)==EDGEDET1)
	{
		CMP->ICR =	EDGEDET1;
	}
	else if((CMP->MISR & EDGEDET3)==EDGEDET3)
	{
		CMP->ICR =	EDGEDET3;				
	}
	else if((CMP->MISR & EDGEDET4)==EDGEDET4)
	{
		CMP->ICR =	EDGEDET4;
	}
}
//-------------------------------------------------------
//-------------------------------------------------------
void MisalignedHandler(void) 
{
    // ISR content ...
	nop;
}

void IllegalInstrHandler(void) 
{
    // ISR content ...
	nop;
}

void AccessErrHandler(void) 
{
    // ISR content ...
	nop;
}

void BreakPointHandler(void) 
{
    // ISR content ...
	nop;
}

void UnrecExecpHandler(void) 
{
    // ISR content ...
	nop;
}

void PriviledgeVioHandler(void) 
{
    // ISR content ...
	nop;
}

void Trap0Handler(void) 
{
    // ISR content ...
	nop;
}

void Trap1Handler(void) 
{
    // ISR content ...
	nop;
}

void Trap2Handler(void) 
{
    // ISR content ...
	nop;
}

void Trap3Handler(void) 
{
    // ISR content ...
	nop;
}

void PendTrapHandler(void) 
{
    // ISR content ...
	nop;
}

void TKEYIntHandler(void)
{
	// ISR content ...
	nop;
}
/******************* (C) COPYRIGHT 2018 APT Chip *****END OF FILE****/